package com.vgooo.client;

import it.sephiroth.android.library.imagezoom.ImageViewTouch;

import java.io.File;

import net.tsz.afinal.FinalBitmap;
import net.tsz.afinal.FinalHttp;
import net.tsz.afinal.http.AjaxCallBack;

import com.umeng.analytics.MobclickAgent;
import com.vgooo.util.BitmapUtils;
import com.vgooo.util.SimpleLoading;
import com.vgooo.util.Utils;
import com.vgooo.client.R;

import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.ViewGroup;

public class ImageZoomActivity extends VGActivity {

	private static String Imagelink;
	
	private ViewGroup layout;
	private ImageViewTouch imageView;
	private FinalHttp fh ;
	

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.zoom_layout);
		layout = (ViewGroup) findViewById(R.id.layout);
		imageView = (ImageViewTouch) findViewById(R.id.image);
	}

	public void initView() {
		//layout.removeAllViews();
		imageView.setImageResource(R.drawable.bg_transparent);
		//this.Imagelink = "http://upload.vgooo.com/images/prodcontentdescimg/20130302/440/1362208999.png";
		String imageLink = Main.imageZoomIntent.getStringExtra("link");
		this.Imagelink =imageLink;
		fh = new FinalHttp();
		String savePath = BitmapUtils.imageCachesPath + BitmapUtils.getImageName(this.Imagelink);
		
		fh.download(this.Imagelink, savePath, new AjaxCallBack<File>() {
			
			@Override
			public void onStart() {
				// TODO Auto-generated method stub
				imageView.setImageResource(R.drawable.bg_transparent);
//				progress = SimpleLoading.startProgress(cparent);
//				progress.start();
			}
			@Override
			public void onLoading(long count, long current) {
				// TODO Auto-generated method stub

			}
			
			@Override
			public void onSuccess(File t) {
				// TODO Auto-generated method stub

				Bitmap bm = BitmapUtils.getBitmap(t.getPath());
				
				imageView.setImageBitmap(bm);
				
//				progress.cancel();
			}
			
			@Override
			public void onFailure(Throwable t, String strMsg) {
				// TODO Auto-generated method stub
			}
		});
		
		
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		// 友盟统计功能，打开页面
		MobclickAgent.onResume(this);
		//隐藏键盘
		Utils.hideSoftInput(imageView);
		initView();
	}
	
	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		// 友盟统计功能，页面关闭
		MobclickAgent.onPause(this);
		super.onPause();
	}
}
